package com.yq;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Enumeration;


//设计一个form表单，点击表单进行提交时，
// 需要获取用户提交的请求参数，
// 同时再次返回给客户端显示，要求可以正常显示中文

@WebServlet("/servlet6")
public class servlet6 extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户的请求参数
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        Enumeration<String> parameterNames = req.getParameterNames();
        PrintWriter writer = resp.getWriter();
        while (parameterNames.hasMoreElements()){
            String key = parameterNames.nextElement();
            String[] parameterValues = req.getParameterValues(key);
            writer.println(key+":"+ Arrays.toString(parameterValues)+"<br>");
        }


    }



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }






}
